import axios from 'axios'

const instance = axios.create({
    baseURL: 'http://520it.com:8881/cms'
});



//请求拦截器
instance.interceptors.request.use( config => {
    console.log('请求拦截器-统一增加token');
    let mytoken = localStorage.getItem('x-auth-token');
    if (mytoken) {
      config.headers['x-auth-token'] = mytoken
    }
    return config;
  },  error => {
    return Promise.reject(error);
  });
  //响应拦截器
  instance.interceptors.response.use(function (response) {
      console.log('响应拦截器',response);
      //此处可以对数据进行二次处理
      //统一在此处提示错误信息
      if (response.data.code != 0 && response.data.code != 400 && response.data.code != 407) {
        alert(response.data.msg);
        return false
      }
    return response.data;
  }, function (error) {
    return Promise.reject(error);
  });
export default instance